package com.ccl.dao;

import com.ccl.entity.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CommentMapper {
    //根据id查询评论数据
    @Select("select * from t_comment where article_id=#{articleId} order by id desc")
    public List<Comment> findCommentsByArticleId(Integer articleId);

    //发表评论
    @Select("insert into t_comment(article_id,created,ip,content,status,author)"+
            "values(#{articleId},#{created},#{ip},#{content},#{status},#{author})"  )
    public void pushComment(Comment comment);

    //统计评论总数
    @Select("select count(*) from t_comment")
    public Integer getCommentsNum();
    //查询最新评论
    @Select("select * from t_comment order by id desc limit #{num}")
    public List<Comment> getRecentComments(Integer num);
    //根据id删除评论内容
    @Delete("delete  from t_comment where id=#{id}")
    public void deleteByArticleId(Integer id);
    //查询所有评论，后台评论管理显示
    @Select("select * from t_comment order by created desc")
    public List<Comment> findAll();
    //删除评论
    @Delete("delete from t_comment where id=#{id}")
    public void deleteById (Integer id);
    //根据评论id查询comment
    @Select("select * from t_comment where id=#{id}")
    public Comment findById(Integer id);
}
